package org.example.documenttool.utils;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import org.example.documenttool.entity.OssAliyun;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

/**
 * OSS工具类
 */
public class OssUtils {
    private static final OSSClientBuilder ossClientBuilder=new OSSClientBuilder();

    /**
     * 上传文件到OSS
     * @param path 获取内容的文件路径
     * @param fileName 输出文件名
     * @return 上传成功返回true，失败返回false
     */
    public static boolean isOssEnabled(Path path,String fileName) throws IOException {
//        TODO 设置OSS公网 密钥 等信息
        try {
            OSS ossClient= ossClientBuilder.build(
                    OssAliyun.ENDPOINT,
                    OssAliyun.ACCESS_KEY_ID,
                    OssAliyun.ACCESS_KEY_SECRET);
            ossClient.putObject(OssAliyun.BUCKET_NAME, fileName, path.toFile());
            return   true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
//        TODO 返回成功失败
        }
}
